<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $this->display();
    }
    public function release() {
          header("Content-type: text/html; charset=utf-8"); 
          date_default_timezone_set('prc');
          $Message = D('message');
          $username = I('post.username', 0);
          $title = I('post.title', 0);
          $content = I('post.content', 0);
          $content = htmlentities($content);
          $xinqing = I('post.xinqing');
          //如果是随机心情，应该产生随机数
          $xinqing = $xinqing == "rand.gif"?mt_rand(1, 7).".gif":$xinqing;
          $act = I('get.act', 0);
          //得到当前的时间戳
          $time = date('y-m-d h:i:s A', time());
          //得到客户端的ip地址
          $ip = $_SERVER['REMOTE_ADDR'];
          @$id = I('get.id', 0);
          //根据不同操作完成不同功能
          if($act == 'addMes') {
              $Message->username = $username;
              $Message->title=$title;
              $Message->content=$content;
              $Message->xinqing=$xinqing;
              $Message->time=$time;
              $Message->ip=$ip;
             
              if($Message->add()) {
                  echo'添加留言成功<br/><a href = "/MMSG_test">继续添加</a> | <a href="/MMSG_test/index.php/Home/message/message">查看留言</a>';
              }else {
                  echo'添加留言失败<br/><a href = "/MMSG_test">重新添加</a>';
              }
          }
          else if($act == 'delMes') {
              $Message->delete($id);
              R('Message/delMes');
          }else if($act == 'editMes') {
              $Message->username = $username;
              $Message->title = $title;
              $Message->content = $content;
              $Message->xinqing = $xinqing;
              if($Message->where("id = $id")->save()) {
                  echo '更新成功<br/>3秒钟之后跳转到查看留言页面';
              }else {
                  echo'更新失败<br/>3秒钟之后跳转到查看留言页面';
              }
              $this->success('', U('message/message'),3);
          }
  
    }

}